home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.0 / stk-3 / blt-for-STk-3.0 / blt-1.9 / man / dragdrop.man < prev    next >
Encoding:
Text File  |  1995-07-01  |  17.8 KB  |  444 lines

  1. '\"
  2. '\" MAN PAGE:  drag&drop widget
  3. '\"   AUTHOR:  Michael J. McLennan
  4. '\"     SCCS:  %W% (%G%)
  5. '\" ========================================================================
  6. '\"                 Copyright (c) 1993  AT&T Bell Laboratories
  7. '\" ========================================================================
  8. '\" Permission to use, copy, modify, and distribute this software and its
  9. '\" documentation for any purpose and without fee is hereby granted,
  10. '\" provided that the above copyright notice appear in all copies and that
  11. '\" both that the copyright notice and warranty disclaimer appear in
  12. '\" supporting documentation, and that the names of AT&T Bell Laboratories
  13. '\" any of their entities not be used in advertising or publicity
  14. '\" pertaining to distribution of the software without specific, written
  15. '\" prior permission.
  16. '\"
  17. '\" AT&T disclaims all warranties with regard to this software, including
  18. '\" all implied warranties of merchantability and fitness.  In no event
  19. '\" shall AT&T be liable for any special, indirect or consequential
  20. '\" damages or any damages whatsoever resulting from loss of use, data or
  21. '\" profits, whether in an action of contract, negligence or other
  22. '\" tortuous action, arising out of or in connection with the use or
  23. '\" performance of this software.
  24. '\" ========================================================================
  25. '\" 
  26. '\" Man page formatting taken from...
  27. '\" Copyright 1992 Regents of the University of California
  28. '\" Permission to use, copy, modify, and distribute this
  29. '\" documentation for any purpose and without fee is hereby
  30. '\" granted, provided that this notice appears in all copies.
  31. '\" The University of California makes no representations about
  32. '\" the suitability of this material for any purpose.  It is
  33. '\" provided "as is" without express or implied warranty.
  34. '\"
  35. .so man.macros
  36. .HS blt_drag&drop cmds
  37. .BS
  38. '\" Note:  do not modify the .SH NAME line immediately below!
  39. .SH NAME
  40. blt_drag&drop \- facilities for handling drag&drop data transfers
  41. .SH SYNOPSIS
  42. \fBblt_drag&drop source
  43. .br
  44. \fBblt_drag&drop source \fIwindow \fR?\fBconfig \fIoptions\fR?
  45. .br
  46. \fBblt_drag&drop source \fIwindow \fBhandler \fR?\fIdataType command\fR ...?
  47. .sp
  48. \fBblt_drag&drop target
  49. .br
  50. \fBblt_drag&drop target \fIwindow \fBhandler \fR?\fIdataType command\fR ...?
  51. .sp
  52. \fBblt_drag&drop target \fIwindow \fBhandle \fIdataType
  53. .sp
  54. \fBblt_drag&drop drag \fIwindow x y
  55. .br
  56. \fBblt_drag&drop drop \fIwindow x y
  57. .br
  58. \fBblt_drag&drop active
  59. .br
  60. \fBblt_drag&drop errors \fR?\fIproc\fR?
  61. .br
  62. \fBblt_drag&drop location \fR?\fIx y\fR?
  63. .BE
  64.  
  65. .SH DESCRIPTION
  66. .PP
  67. The \fBblt_drag&drop\fR command provides access to a set of facilities
  68. for managing drag-and-drop data transfers.  Any of the usual Tk widgets can
  69. be registered to participate in the drag-and-drop process.  Widgets
  70. registered as a drag&drop \fIsource\fP can export data to other widgets
  71. registered as a drag&drop \fItarget\fP.  Note that a particular widget
  72. can be registered as a source, as a target, or as both.
  73. .PP
  74. The drag-and-drop process begins when the user clicks and holds a mouse
  75. button in a source window; a token window appears with an icon or message
  76. to represent the data being transferred.  As the user moves the mouse pointer,
  77. the token window follows along, acting as a movable packet of data.
  78. Whenever the mouse pointer falls on a valid target window, the border of the
  79. token window is changed to a raised (active) state.  When the mouse button is
  80. released over the target window, a Tcl routine is invoked to send the data
  81. to the desired application.  If this communication process fails,
  82. a rejection symbol (a circle with a line through it) is displayed
  83. on the token window to indicate failure.
  84. .PP
  85. The details of the communication process are fully configurable by the
  86. application developer.  The general philosophy, however, is that the
  87. sender should invoke a series of commands in the remote application to
  88. transfer data into a buffer, and then request that the receiver "handle"
  89. the data.  For example, the sender might invoke a command like
  90. \fB"set DragDrop(number) 12.3"\fP in the target application.
  91. The sender would then request that the target "handle" a "number".  This
  92. separation between the data sent and the means of handling it is critical.
  93. It allows the developer a simple means of having several targets that all
  94. receive "numbers" but use them in different ways.
  95. .PP
  96. Both sources and targets must be registered with a list of "handlers"
  97. defining the data types that they recognize.  As a token window is
  98. dragged from its source to various targets, each target is checked to
  99. see if it recognizes a "handler" offered by the source.  If it does,
  100. it is treated as a "valid" target.  Otherwise, it is ignored.  This
  101. scheme allows the same source to interact with many different kinds of
  102. targets.  A source for RGB color samples, for instance, might have
  103. "color" and "text" handlers.  This would allow it to communicate with
  104. "color" targets (sending RGB data) as well as entry widgets (sending
  105. strings of the form "#rrggbb").
  106. .PP
  107. For drag&drop to be effective across many applications, handlers for
  108. \fIsending\fR various data types should be common.  For this reason,
  109. a directory "demos/dd_protocols" containing a number of example handlers
  110. is included with this distribution.  Developers are encouraged to
  111. use this library and contribute new functions.
  112. .PP
  113. This introduction was presented as a brief overview of the communication
  114. process; further details are presented below:
  115. .TP
  116. \fBblt_drag&drop source\fR
  117. Returns a list of path names for widgets registered as drag&drop
  118. sources.  Returns an empty string if no widgets have been registered.
  119. .TP
  120. \fBblt_drag&drop source \fIwindow \fR?\fBconfig \fIoptions\fR?
  121. Registers a new drag&drop source window with the given options, or
  122. modifies the options for an existing window:
  123. .RS
  124. .LP
  125. .nf
  126. Name:    \fBbuttonBinding\fR
  127. Class:    \fBButtonBinding\fR
  128. Switch:    \fB\-button\fR \fIn\fR
  129. .fi
  130. .IP
  131. Specifies the mouse button (integer 1-5) that will invoke the drag&drop
  132. operation on the source window.  This causes the following bindings to
  133. be added to the widget:
  134. .sp
  135. .nf
  136. .RS
  137. \f(CWbind \fIwin\fP <ButtonPress-\fIn\fP> {blt_drag&drop drag %W %X %Y}
  138. \f(CWbind \fIwin\fP <B\fIn\fP-Motion> {blt_drag&drop drag %W %X %Y}
  139. \f(CWbind \fIwin\fP <ButtonRelease-\fIn\fP> {blt_drag&drop drop %W %X %Y}\fR
  140. .RE
  141. .fi
  142. .sp
  143. The default value is button 3.  If the value "0" is specified, then no
  144. bindings are added; this enables the user to establish bindings manually.
  145. .LP
  146. .nf
  147. Name:    \fBpackageCommand\fR
  148. Class:    \fBCommand\fR
  149. Switch:    \fB\-packagecmd \fIprefix\fR
  150. .fi
  151. .IP
  152. Specifies a Tcl command used to establish the appearance of the token window
  153. at the start of each drag&drop operation.  This command is automatically
  154. invoked by the \fBblt_drag&drop drag\fP command whenever the token window
  155. is about to be mapped for a drag operation.  The path name for the token
  156. window is automatically appended to the command before it is executed:
  157. .sp
  158. .nf
  159. .RS
  160. \fIpackagecmd token\fR
  161. .RE
  162. .fi
  163. .sp
  164. Typically, this command is the name of a procedure (taking the token window
  165. argument) which will pack a label--or update the text of a label--in the
  166. token window.
  167. .LP
  168. The return value from the package command is later passed as an argument
  169. to the send handler; thus, it is the responsibility of the package command
  170. to determine what information will later be sent.  For complex sources,
  171. such as a listbox containing a number of items, the package command can use
  172. the \fBblt_drag&drop location\fR command to determine the part of a widget
  173. that a user has selected and extract a value.  For example, the following
  174. package routine will select an item from a listbox and configure the token
  175. window to display the selected string:
  176. .sp
  177. .nf
  178. .RS
  179. \f(CWproc package_list_item {lbox token} {
  180.     if {[winfo children $token] == ""} {
  181.         label $token.value
  182.         pack $token.value
  183.     }
  184.     set xy [blt_drag&drop location]
  185.     set y  [expr [lindex $xy 1]-[winfo rooty $lbox]]
  186.  
  187.     set str [$lbox get [$lbox nearest $y]]
  188.     $token.value config -text $str
  189.     return $str
  190. }\fR
  191. .RE
  192. .fi
  193. .sp
  194. If the package command returns an empty string, the drag operation is
  195. quietly aborted.  This can be used to disallow drag&drop operations from
  196. certain parts of a widget, if the drag position is inappropriate.
  197. .LP
  198. .nf
  199. Name:    \fBrejectBackground\fR
  200. Class:    \fBBackground\fR
  201. Switch:    \fB\-rejectbg \fIcolor\fR
  202. .fi
  203. .IP
  204. Specifies the color used to draw the background of the rejection symbol
  205. on the token window.  The rejection symbol (a circle with a line through
  206. it--the international "no") appears whenever communication fails.
  207. .LP
  208. .nf
  209. Name:    \fBrejectForeground\fR
  210. Class:    \fBForeground\fR
  211. Switch:    \fB\-rejectfg \fIcolor\fR
  212. .fi
  213. .IP
  214. Specifies the color used to draw the foreground of the rejection symbol
  215. on the token window.
  216. .LP
  217. .nf
  218. Name:    \fBrejectStipple\fR
  219. Class:    \fBStipple\fR
  220. Switch:    \fB\-rejectstipple \fIpattern\fR
  221. .fi
  222. .IP
  223. Specifies a stipple pattern used to draw the foreground of the rejection
  224. symbol on the token window.  Any of the forms acceptable to Tk_GetBitmap
  225. can be used.
  226. .LP
  227. .nf
  228. Name:    \fBselfTarget\fR
  229. Class:    \fBSelfTarget\fR
  230. Switch:    \fB\-selftarget \fIboolean\fR
  231. .fi
  232. .IP
  233. If the \fIboolean\fR value is true, and if a source widget is also
  234. registered as a compatible target, then the source will be able to transmit
  235. to itself during drag&drop operations.  This is primarily useful for
  236. complex sources such as a canvas widget, where items may be moved from
  237. place to place within the same widget.  By default, this option is disabled.
  238. .LP
  239. .nf
  240. Name:    \fBsend\fR
  241. Class:    \fBSend\fR
  242. Switch:    \fB\-send \fIlist\fR
  243. .fi
  244. .IP
  245. Specifies a \fIlist\fR of \fIdataTypes\fR enabled for communication.  Only
  246. \fIdataTypes\fR defined by commands of the form "\fBblt_drag&drop source
  247. \fIwindow \fBhandler \fR?\fIdataType command\fR ...?" are allowed.
  248. This list also determines the priority of the various \fIdataTypes\fR.
  249. When a token window is over a potential drag&drop target, this list is
  250. searched from start to finish for a \fIdataType\fR that is also recognized
  251. by the target.  The first matching \fIdataType\fR found determines the
  252. value that will be sent if the token is dropped.  If no matching \fIdataType\fR
  253. is found, then the target is incompatible, and is ignored.  By default,
  254. this option has the value "all", indicating that all \fIdataTypes\fR should
  255. be considered in the order that they were defined for the source.
  256. .LP
  257. Note that this option makes it easy to control a drag&drop source.  Setting
  258. the value to an empty string disables the source; setting the value back
  259. to "all" restores communication.
  260. .LP
  261. .nf
  262. Name:    \fBsiteCommand\fR
  263. Class:    \fBCommand\fR
  264. Switch:    \fB\-sitecmd \fIprefix\fR
  265. .fi
  266. .IP
  267. Specifies a Tcl command used to update the appearance of the token window.
  268. If specified, this command is automatically invoked by the
  269. \fBblt_drag&drop drag\fP command whenever the token window is over a
  270. compatible drag&drop target.  Two arguments are appended to this command:
  271. .sp
  272. .nf
  273. .RS
  274. \fIsitecmd state token\fR
  275. .RE
  276. .fi
  277. .sp
  278. \fIstate\fR is an integer with a non-zero value whenever the token
  279. window is over a compatible target, and \fItoken\fR is the path for the
  280. token window.  Regardless of this command, border of the token window
  281. will become raised whenever the token is over a valid target.  This
  282. command can be used to display other visual cues.
  283. .LP
  284. .nf
  285. Name:    \fBtokenAnchor\fR
  286. Class:    \fBAnchor\fR
  287. Switch:    \fB\-tokenanchor \fIanchor\fR
  288. .fi
  289. .IP
  290. Specifies how the token window is positioned relative to the mouse
  291. pointer coordinates passed to the \fBblt_drag&drop drag\fP command.
  292. Must be one of the values n, s, e, w, center, nw, ne, sw or se.
  293. For example, "nw" means to position the token such that its upper-left
  294. corner is at the mouse pointer.  The default value is "center".
  295. .LP
  296. .nf
  297. Name:    \fBtokenBackground\fR
  298. Class:    \fBBackground\fR
  299. Switch:    \fB\-tokenbg \fIcolor\fR
  300. .fi
  301. .IP
  302. Specifies the color used to draw the background of the token window.
  303. .LP
  304. .nf
  305. Name:    \fBtokenBorderWidth\fR
  306. Class:    \fBBorderWidth\fR
  307. Switch:    \fB\-tokenborderwidth \fIsize\fR
  308. .fi
  309. .IP
  310. Specifies the width in pixels of the border around the token window.
  311. This border becomes raised to indicate when the token is over a compatible
  312. drag&drop target site.  The value may have any of the forms acceptable
  313. to Tk_GetPixels.  The default value is "3".
  314. .LP
  315. .nf
  316. Name:    \fBtokenCursor\fR
  317. Class:    \fBCursor\fR
  318. Switch:    \fB\-tokencursor \fIcursor\fR
  319. .fi
  320. .IP
  321. Specifies the cursor used when a token window is active.  The value
  322. may have any of the forms acceptable to Tk_GetCursor.  The default
  323. value is "center_ptr".
  324. .RE
  325. .TP
  326. \fBblt_drag&drop source \fIwindow \fBhandler \fR?\fIdataType command\fR ...?
  327. Defines one or more \fIdataTypes\fR available for communication, and the
  328. \fIcommands\fR used to send them to remote applications.  If no \fIdataTypes\fR
  329. are specified, then the list of previously defined \fIdataTypes\fR is returned.
  330. .LP
  331. Each \fIcommand\fR represents a Tcl command prefix.  Three arguments are
  332. appended to this prefix when communication is initiated for a particular
  333. \fIdataType\fR:
  334. .sp
  335. .nf
  336. .RS
  337. \fIcommand interp target data\fR
  338. .RE
  339. .fi
  340. .sp
  341. \fIinterp\fR is the name of the interpreter containing the target widget;
  342. \fItarget\fR is the name of the target widget; and \fIdata\fR is the data
  343. string returned from the "package" command invoked at the start of the
  344. drag&drop operation.
  345. .LP
  346. A typical source handler contains one or more "send" commands which
  347. transfer data to the remote application, followed by a "\fBblt_drag&drop
  348. ... handle\fR command" (described below) requesting that the target
  349. widget handle the incoming data.  An example source handler for a "text"
  350. data type is shown below:
  351. .sp
  352. .nf
  353. .RS
  354. \f(CWproc dd_send_text {interp ddwin data} {
  355.     send $interp "
  356.         global DragDrop
  357.         set DragDrop(text) {$data}
  358.     "
  359.     send $interp "blt_drag&drop target $ddwin handle text"
  360. }\fR
  361. .RE
  362. .fi
  363. .sp
  364. This handler transfers the text string to a global variable DragDrop(text)
  365. in the target interpreter, and then requests that the target "handle" the
  366. incoming data.  This separation between the transfer and the handling of
  367. the data is important.  It allows the same source handler to transfer data
  368. for many different targets, and it allows each of the targets to handle
  369. the incoming data differently.  If an error is encountered during the
  370. communication process, the rejection symbol is posted on the token window
  371. to indicate failure.
  372. .RE
  373. .sp
  374. .TP
  375. \fBblt_drag&drop target\fR
  376. Returns a list of path names for widgets registered as drag&drop
  377. targets.  Returns an empty string if no widgets have been registered.
  378. .TP
  379. \fBblt_drag&drop target \fIwindow \fBhandler \fR?\fIdataType command\fR ...?
  380. Registers a new drag&drop target window with the given handlers, or
  381. modifies the handlers for an existing window.  If no handlers are
  382. specified, this command returns the current list of recognized
  383. \fIdataType\fR strings.  Each \fIdataType\fR is a symbolic name
  384. representing a form of data, and the corresponding \fIcommand\fR is
  385. a Tcl command that specifies how the target will make use of the data.
  386. This command is invoked indirectly whenever a send routine transmits
  387. data and then issues the "blt_drag&drop ... handle \fIdataType\fR" command
  388. to make use of it.
  389. .TP
  390. \fBblt_drag&drop target \fIwindow \fRhandle \fIdataType
  391. Searches for the given \fIdataType\fR name among the handlers registered
  392. for the target \fIwindow\fR, and invokes the appropriate \fIcommand\fR.
  393. If the \fIdataType\fR name is not recognized, this command returns an
  394. error.  Typically, this command is invoked by one of the send handlers
  395. for a drag&drop source.
  396. .TP
  397. \fBblt_drag&drop drag \fIwindow x y\fR
  398. Marks the start of (or movement during) a drag&drop operation.  If
  399. the token window is unmapped when this command is invoked, then the
  400. \fB\-packagecmd\fR for the source \fIwindow\fR is executed.  If this
  401. command is successful and returns a non-null string, the token window
  402. is mapped.  On subsequent calls, the token window is moved to the new
  403. \fIx y\fR location.  Unless the "\fB\-button 0\fR" option is specified for
  404. the source, this command is automatically bound to <ButtonPress-\fIn\fR>
  405. and <B\fIn\fR-Motion> events for "\fB\-button \fIn\fR" of the source widget.
  406. .TP
  407. \fBblt_drag&drop drop \fIwindow x y\fR
  408. Marks the end of a drag&drop operation.  If the mouse pointer is
  409. over a compatible target window, then the appropriate send handler for
  410. the first compatible \fIdataType\fR is invoked to handle the data transfer.
  411. If the data transfer is successful, then the token window is unmapped;
  412. otherwise, a rejection symbol is drawn on the token window, and the window
  413. is unmapped after a small delay.  Unless the "\fB\-button 0\fR" option is
  414. specified for the source, this command is automatically bound to the
  415. <ButtonRelease-\fIn\fR> event for "\fB\-button \fIn\fR" of the source widget.
  416. .TP
  417. \fBblt_drag&drop active\fR
  418. Returns "1" if a drag&drop operation is in progress, and "0" otherwise.
  419. A drag&drop operation officially starts after the package command has
  420. been executed successfully, and ends after the send handler has been
  421. executed (successfully or otherwise).
  422. .TP
  423. \fBblt_drag&drop errors \fR?\fIproc\fR?
  424. Specifies a Tcl \fIproc\fR used to handle errors encountered during
  425. drag&drop operations.  If a \fIproc\fR is not specified, this command
  426. returns the current error handler.  By default, all errors are sent
  427. to the usual \fBtkerror\fR command, and therefore appear in a dialog
  428. box to the user.  This behavior is quite useful when debugging
  429. communication protocols, but may not be desirable in a finished
  430. application.  Errors can be suppressed entirely (leaving the rejection
  431. symbol as the only error indicator) by specifying a null string in
  432. place of the \fIproc\fR name.
  433. .TP
  434. \fBblt_drag&drop location \fR?\fIx y\fR?
  435. Used to set or query the pointer location during a drag&drop operation.
  436. The \fIx y\fR arguments specify the current location; if these arguments
  437. are missing, then the last reported (x,y) location is returned as a list
  438. with two elements.  This command is issued automatically within the
  439. \fBblt_drag&drop drag\fR and \fBblt_drag&drop drop\fR commands, to
  440. keep track of pointer movement.
  441.  
  442. .SH KEYWORDS
  443. drag&drop, send, bind, widget
  444.